"; if($row['ImageUrl']) $imgHtml = "$imgHtml"; } echo $imgHtml; } ?>
Live chat for website
2 AND Deleted=0 AND LEFT(Description, 1)!='.' "; global $PromoIcon; //echo("it is $query"); if(strlen($PromoIcon) > 0) { $query .= " AND PromoIcon = '".str_replace("'", "''", $PromoIcon)."' and PromoIconStartDate <= CURDATE() and CURDATE() <= PromoIconEndDate"; //echo("
1 $query"); } // $query .= " AND " if($categoryStr) $query .= " /*AND g.ID_catalogue IS NOT NULL OR (1=1*/"; //echo("reseller is ".IsReseller()); // The search term: posted on the first search, carried via GET on paginated // pages (pg=2..). Empty when btnSearch is present without a term (e.g. a bare // ?btnSearch=1) - in that case we must NOT enter the search branch, because // FulltextQuery() calls exit() on an empty term and would blank the page. $searchTermReq = strlen($_POST['txtSearch']) ? $_POST['txtSearch'] : $_GET['txtSearch']; $hasSearch = isset($btnSearch) && strlen($searchTermReq) > 0; if(IsReseller() && decryptwithkey($_COOKIE["reseller"]) != "vip")//* is a VIP with reseller pricing { if($selectedBrand || $_GET['item1']) { if($selectedBrand) $query .= " AND Brand='$selectedBrand'"; if($_GET['item1']) { $query .= " AND MenuItem1='$item1'"; if($_GET['item2']) { $query .= " AND MenuItem2='$item2'"; if($_GET['item3']) $query .= " AND MenuItem3='$item3'"; } } $query .= " AND ".GetUserLikeClause($dbh,$user); //echo("reseller query 1 ".$query); } elseif($hasSearch) { $query = FulltextQuery("*", $searchTermReq) . " AND ".GetUserLikeClause($dbh,$user); } elseif($_GET['tag']) { $query .= " AND Tags LIKE '%*{$_GET['tag']}*%'" . " AND ".GetUserLikeClause($dbh,$user); } else $query .= " AND OnHomePageUser=1"; //echo("reseller query ".$query); } else // Normal customers { if($selectedBrand || $_GET['item1']) { if($selectedBrand) $query .= " AND Brand='$selectedBrand'"; if($_GET['item1']) { $query .= " AND ((MenuItem1='$item1'"; if($_GET['item2']) { $query .= " AND MenuItem2='$item2'"; if($_GET['item3']) $query .= " AND MenuItem3='$item3'"; } $query .= ")"; if($categoryStr) { $query .= " or g2.Product_type = '$categoryStr'"; } $query .= ")"; } $query .= " AND Size <> 2 AND LEFT(Description, 1)!='.' "; } elseif($hasSearch) $query = FulltextQuery("*", $searchTermReq); elseif(strlen($_GET['txtSearch']) > 0) $query = FulltextQuery("*", $_GET['txtSearch']); elseif($_GET['tag']) $query .= " AND Tags LIKE '%*{$_GET['tag']}*%'"; elseif(strlen($PromoIcon) === 0) $query .= " AND OnHomePage=1"; //echo("
2 $query"); //echo("222"); } if($categoryStr) ;/*$query .= ")";*/ $query .= $query_multi_category; if(strpos(strtoupper($query),"ORDER BY") === false) { if(strlen($PromoIcon) > 0) { $query .= " ORDER BY MenuItem1"; } else { $query .= " ORDER BY Identifier"; } } //if(strlen($PromoIcon) > 0) // echo $query; if(strlen($PromoIcon) > 0) { PrintTableProductsPromoIcon($query); } else { PrintTableProducts($query); } ?> Home"; if($_GET['item1']) { if($_GET['item2']) $breadcrumbs .= " > {$_GET['item1']}"; else $breadcrumbs .= " > {$_GET['item1']}"; } if($_GET['item2']) { if($_GET['item3']) $breadcrumbs .= " > {$_GET['item2']}"; else $breadcrumbs .= " > {$_GET['item2']}"; } if($_GET['item3']) $breadcrumbs .= " > {$_GET['item3']}"; } $lastIdentifier = false; // Print a table listing all products that matches the query // Query is like "SELECT * FROM Catalogue WHERE Item1='CAMERA' AND Size<>2 AND Deleted=0" function PrintTableProducts($query) { global $dbh; $childProducts = GetChildProducts($dbh); //echo $query . "
"; //print_r($childProducts); /*if ($_SERVER['REMOTE_ADDR'] == '220.245.174.83') print $query."
"; */ YartLog($query); $result = mysql_query($query, $dbh); ///echo("111 ".$query); $availabilities = GetExistingAvailabilities($dbh); PrintAvailabilities($dbh, $availabilities); $numResults = mysql_num_rows($result); YartLog("numResults: ".$numResults); $products = array(); $i = 0; while( $row = mysql_fetch_array($result) ) { //echo("
Id: ".$row["ID"]); $products[$i] = $row; YartLog("adding results to array"); $i++; } if($numResults == 0) // no results { echo "

No products found matching your criteria.

"; return; } // Collect the rows that will actually be displayed (after the parent/child // dedup below), then paginate the display so a broad search or category // doesn't dump every match onto one page. $toRender = array(); $count = 0; $cols = 2; $parent_index = 0; // Index the result rows and the child list by ID so the dedup loop can do // O(1) lookups instead of rescanning the whole array for every product. // Behaviour is identical to the old linear scans (IsChild / the inner // "is the parent in the results" loop), just without the O(n^2) cost. $resultIdSet = array(); for($k = 0; $k < count($products); $k++) $resultIdSet[$products[$k]["ID"]] = true; $childIdSet = array(); for($k = 0; $k < count($childProducts); $k++) $childIdSet[$childProducts[$k]["ID"]] = true; for($i = 0; $i < count($products); $i++) // $row = mysql_fetch_array($result) ) { $row = $products[$i]; $flag = false; $parentInSearchResults = false; if (isset($childIdSet[$row["ID"]])) { $parent = GetParent($dbh, $row["ID"], $parent_index++); //YartLog(print_r($parent)); // Same as the old inner scan: is this child's parent also present // in the result set? ($parent is false when none was found.) $parentInSearchResults = ($parent !== false) && isset($resultIdSet[$parent["ID"]]); if (!$parentInSearchResults) { //echo "2
"; $row = $parent; } } else { $parent_index = 0; } // echo $row["Identifier"] == $lastIdentifier; //echo IsChild($childProducts, $row["ID"]); if ($parentInSearchResults) { if ( $row["Identifier"] == $lastIdentifier || isset($childIdSet[$row["ID"]])) { //echo "3
"; continue; } }else { if ( $row["Identifier"] == $lastIdentifier) { continue; } } //echo "3
"; $lastIdentifier = $row["Identifier"]; /* if ($row) { if($count % $cols == 0) echo " \n"; if(($count+1) % $cols == 0) echo " \n"; else echo " \n"; */ //echo("
Id 1: ".$row["ID"]); $toRender[] = $row; /* echo " \n"; if(($count+1) % $cols == 0) echo " \n"; $count++; }*/ } /* if($count%$cols != 0) { echo "  \n"; echo " \n"; }*/ // ---- Paginate the display ---- $perPage = 24; $totalItems = count($toRender); $totalPages = max(1, (int)ceil($totalItems / $perPage)); $pageNum = isset($_GET['pg']) ? (int)$_GET['pg'] : 1; if($pageNum < 1) $pageNum = 1; if($pageNum > $totalPages) $pageNum = $totalPages; $startIndex = ($pageNum - 1) * $perPage; $endIndex = min($startIndex + $perPage, $totalItems); // Work out the current search term (posted first time, carried via GET on later pages) $searchTerm = (isset($_POST['txtSearch']) && strlen($_POST['txtSearch'])) ? $_POST['txtSearch'] : $_GET['txtSearch']; $isSearch = ($_POST['btnSearch'] || $_GET['btnSearch']) && strlen($searchTerm) > 0; // Preserve the current filters (search term, category, brand, tag) in the page links $pageParams = $_GET; unset($pageParams['pg']); if($isSearch) { $pageParams['btnSearch'] = 1; $pageParams['txtSearch'] = $searchTerm; } $youSearched = $isSearch ? "You searched for ".htmlspecialchars($searchTerm).". " : ''; $firstShown = $totalItems == 0 ? 0 : $startIndex + 1; echo "

${youSearched}Showing {$firstShown}–{$endIndex} of {$totalItems} items.

"; PrintPagination($pageNum, $totalPages, $pageParams); echo "
\n"; for($i = $startIndex; $i < $endIndex; $i++) { PrintProductDetailsDiv($toRender[$i], $availabilities, $products, $childProducts); } echo "
\n"; PrintPagination($pageNum, $totalPages, $pageParams); } // Print numbered pagination links, preserving the current filters in $pageParams function PrintPagination($pageNum, $totalPages, $pageParams) { if($totalPages <= 1) return; echo "\n"; } // Build a single pagination anchor, keeping the current filters and setting the target page function PageLink($pageParams, $p, $label, $class) { $pageParams['pg'] = $p; $href = htmlspecialchars('?'.http_build_query($pageParams)); $cls = $class ? " class=\"$class\"" : ''; return " $label\n"; } function PrintTableProductsPromoIcon($query) { global $dbh; $childProducts = GetChildProducts($dbh); //echo $query; //print_r($childProducts); $result = mysql_query($query, $dbh); //echo $query."
"; $availabilities = GetExistingAvailabilities($dbh); PrintAvailabilities($dbh, $availabilities); $numResults = mysql_num_rows($result); $products = array(); $i = 0; while( $row = mysql_fetch_array($result) ) { $products[$i] = $row; $i++; } if($numResults == 0) // no results { echo "

No products found matching your criteria.

"; return; } $youSearched = ''; if(($_POST['btnSearch'] || $_GET['btnSearch']) && $_POST['txtSearch']) $youSearched = "You searched for {$_POST['txtSearch']}. "; echo "

${youSearched}Showing " . UniqueProducts($products, $childProducts) . " items.

"; echo "
\n"; mysql_data_seek($result, 0); $count = 0; $cols = 2; $lastMenuItem1 = ""; $parent_index = 0; for($i = 0; $i < count($products); $i++) // $row = mysql_fetch_array($result) ) { $row = $products[$i]; $flag = false; if (IsChild($childProducts, $row["ID"])) { //echo "here".$row["ID"]; $parent = GetParent($dbh, $row["ID"], $parent_index++); //print_r($parent); $parentInSearchResults = false; for ($j = 0; $j < count($products); $j++) { //echo "0
{$products[$j]["ID"]}, {$parent["ID"]}"; if ($products[$j]["ID"] == $parent["ID"]) { //echo "1
"; $parentInSearchResults = true; break; } } if (!$parentInSearchResults) { //echo "2
"; $row = $parent; } }else { $parent_index = 0; } // echo $row["Identifier"] == $lastIdentifier; //echo IsChild($childProducts, $row["ID"]); if ($row["Identifier"] == $lastIdentifier || IsChild($childProducts, $row["ID"])) { //echo "3
"; continue; } //echo "3
"; $lastIdentifier = $row["Identifier"]; if (count($row) > 1 && trim($lastMenuItem1) != trim($row["MenuItem1"])) { //echo "
lastMenuItem1 is $lastMenuItem1 row[MenuItem1] is ".$row["MenuItem1"] ."count row is ".count($row); //print_r($row); //echo "
"; //echo " ". $row["MenuItem1"] . "
\n"; echo "
". $row["MenuItem1"] . "
\n"; $lastMenuItem1 = $row["MenuItem1"]; $count = 0; } if ($row) { /*if($count % $cols == 0) echo " \n"; if(($count+1) % $cols == 0) echo " \n"; else echo " \n";*/ PrintProductDetailsDiv($row, $availabilities, $products, $childProducts); /*echo " \n"; if(($count+1) % $cols == 0) echo " \n";*/ $count++; } } /* if($count%$cols != 0) { echo "  \n"; echo " \n"; } */ echo " \n"; } // $row = a row from the Catalogue table function PrintProductDetailsDiv($row, $availabilities, $products, $childProducts) { global $currency, $dbh, $user; //echo("
PrintProductDetailsDiv: ".$row["Identifier"]); $id = $row["ID"]; $identifier = $row["Identifier"]; $name = $row["Brand"] . " " . $row["Description"]; $specialPrice = $row["On_special"]; $thumbFile = MediaUrl($row["thumbnail"]); $desc = $row["ShortDescription"]; $size = $row["Size"]; $promoIcon = $row["PromoIcon"]; $promoIconStartDate = $row["PromoIconStartDate"]; $promoIconEndDate = $row["PromoIconEndDate"]; $minQuantity = $row["minQuantity"]; $maxQuantity = $row["maxQuantity"]; $stock = $row["Stock"]; $suppressStockWarning = $row["suppressStockWarning"]; if($suppressStockWarning == 1) { $stock = 100000; } $children = GetChildren($dbh, $id, $childProducts); //echo "id - ".$id; //$price = $row["Price1_no_sales_tax"]; if(IsReseller()) { ///echo "111"; $price = UnitPriceNoTaxReseller($row, $dbh); } else { //echo "222"; $price = UnitPriceNoTax($row, $dbh); //echo "price is $price"; } if(strlen($thumbFile) == 0) { $thumbFile = "images/no_image.gif"; } //echo "id1 - ".$id; $specialText = ""; $currencyDisplay = $currency; $applyGst = $row["ApplyGst"]; $hasNoGst = false; if ($applyGst == 0) $hasNoGst = true; if ($hasNoGst) { if ($currencyDisplay == "AUD inc. Tax") { $currencyDisplay = "AUD No GST"; } else { //echo("it is 1"); $price = CurrencyConvert($price, $currency); //echo("it is 2"); } $hasNoGst = true; } else { //echo("it is 3"); $price = CurrencyConvert($price, $currency); //echo("it is 4"); } $priceText = "\$$price
"; //echo("it is 11"); $oriPrice = CurrencyConvert($row["Price1_no_sales_tax"], $currency); //echo("it is 22"); //echo("
specialPrice is $specialPrice"); //echo("
price is ".intval($price * 100)); //echo("
oriPrice is ".intval($oriPrice * 100)); if($specialPrice > 0) { //$specialText = "
On Special
"; if($oriPrice && $price && $price!=$oriPrice) { $orginPrice = floatval(str_replace(",","",$oriPrice)); $disCountprice = floatval(str_replace(",","",$price)); $percentage = round((($orginPrice-$disCountprice)/$orginPrice) * 100.0); $specialText = "
".$percentage."%
off
"; } } if(($specialPrice > 0 || IsReseller()) && $price != $oriPrice) { //echo("
oriPrice is $oriPrice"); $priceText .= "\n$$oriPrice
"; } $priceText .= "($currencyDisplay)"; //echo("it is 111"); $noFreightText = ""; if(HasNoFreight($identifier) == 1) $noFreightText = "
"; //echo("it is 222"); //echo("it is 1"); $sizeHtml = GetSizeDropdownHtml($id, $row['Size'], $identifier); //echo("it is 2"); $childrenDropDown = GetChildrenDropDown($row, $children); //echo("it is 3"); $qtyHtml = ""; if($row["Quantity2"]) $qtyHtml = "
Quantity Price"; if(strlen($promoIcon) > 0) { if(strtotime($promoIconStartDate) <= time() && time() <= strtotime($promoIconEndDate)) $promoIconImage = "\"".PromoIconDescription($promoIcon)."\""; else { //echo("
promoIconStartDate is $promoIconStartDate"); //echo("
promoIconEndDate is $promoIconEndDate"); //echo("
date is ".date_default_timezone_get()); } } if($id) { $productName = ProductName($id, $identifier, $name); echo <<< END
$productName
$specialText
$priceText
$promoIconImage $desc More...

Order
$sizeHtml
END; PrintAvailability($row, $availabilities); echo <<< END
$qtyHtml $childrenDropDown $noFreightText
END; } } function ProductName($id, $identifier, $name) { // The version this replaced (in functions.php) took $dbh as a fourth // parameter; here it has to come from the global, or mysql_query() gets null. global $dbh; $productName = ""; $query = "select Text from GroupedProductName where ParentProductId=$id"; $result = mysql_query($query, $dbh); $row = mysql_fetch_array($result); $name = preg_replace('/\s+/', ' ', $name); if($row) { $productName .= '
'.$row[0].'
'.$name.'
'; } else { $product_name = $name." (".$identifier.")"; $productName .= '
'.$product_name.'
'; } return $productName; } function PrintAvailability($row, $availabilities) { if($row['Stock'] > 0) { PrintAvailabilityDirect1($row, $availabilities); } else { $deliveryDate = GetOutOfStockDeliveryDate($row); if($deliveryDate) { PrintOutOfStockDateTimes($row, $deliveryDate); } else { PrintAvailabilityDirect1($row, $availabilities); } } } function GetOutOfStockDeliveryDate($row) { global $dbh; $stockCat = $row['STOCK_CAT']; // Get the Days for this STOCK_CAT from OutOfStockDeliveryTimes $query = "SELECT Days FROM OutOfStockDeliveryTimes WHERE CategoryStart <= '$stockCat' AND CategoryEnd >= '$stockCat' LIMIT 1"; $result = mysql_query($query, $dbh); if(!$result || !($daysRow = mysql_fetch_array($result))) { return false; } $days = $daysRow['Days']; // Get the base DeliveryDate from OutOfStockDeliveryDate $query = "SELECT DeliveryDate FROM OutOfStockDeliveryDate LIMIT 1"; $result = mysql_query($query, $dbh); if(!$result || !($dateRow = mysql_fetch_array($result))) { return false; } // Calculate actual delivery date = DeliveryDate + Days return strtotime($dateRow['DeliveryDate'] . " + $days days"); } function PrintOutOfStockDateTimes($row, $deliveryDate) { $deliveryDate = GetOutOfStockDeliveryDate($row); if($deliveryDate) { $formatted = date('jS F Y', $deliveryDate); echo("ETA: $formatted"); } } function PrintAvailabilityDirect1($row, $availabilities) { $availability_code = $row['Availability']; $keys = -1; $shortDescription = ''; $longDescription = ''; $outofstock = 'outofstock'; if($row['Stock'] > 0) { //PrintAvailabilityDirect($row, "NOW IN STOCK", "This item is currently IN STOCK in our AUSTRALIAN warehouse and can be collected from our store or ordered online and it will be shipped immediately.* Please contact us for more information. (conditions apply)", "isX"); $availability_code = "isX"; $shortDescription = $availabilities[$availability_code][0]; $longDescription = $availabilities[$availability_code][1]; //PrintAvailabilityDirect($row, "NOW IN STOCK", "", ""); PrintAvailabilityDirect($row, $shortDescription, $longDescription, $availability_code); } else { if(AvailabilityExists($availabilities, $availability_code)) { $shortDescription = $availabilities[$availability_code][0]; $longDescription = $availabilities[$availability_code][1]; echo "

". $availability_code ."

"; PrintAvailabilityDirect($row, $shortDescription, $longDescription, $availability_code); } else if(!AvailabilityExists($availabilities, $availability_code)) { $shortDescription = $availabilities[$outofstock][0]; $longDescription = $availabilities[$outofstock][1]; PrintAvailabilityDirect($row, $shortDescription, $longDescription, $outofstock); } } } function PrintAvailabilityDirect($row, $shortDescription, $longDescription, $availability_code) { $style = ""; if($shortDescription == "BACK ORDER") { $shortDescription = "NO STOCK - BACK ORDER"; $style = " style=\"display:flex\" "; } echo("\n\n
"); $shortDescription = str_replace('
', ' - ', $shortDescription); echo("\n
$shortDescription
"); if(strlen($availability_code) > 0 && strlen(trim($longDescription)) > 0) echo("\n\"Help\""); echo("\n
\n\n"); } function GetParent($dbh, $id, $parent_index) { //$query = "select * from Catalogue right join GroupedProducts on Catalogue.ID = GroupedProducts.ChildCatalogueId right join GroupedProductName on GroupedProductName.GroupedProductNameId = GroupedProducts.GroupedProductNameId where ChildCatalogueId = $id"; $query = "select * from Catalogue right join GroupedProductName on Catalogue.Id = GroupedProductName.ParentProductId right join GroupedProducts on GroupedProducts.GroupedProductNameId = GroupedProductName.GroupedProductNameId where GroupedProducts.ChildCatalogueId = $id and Identifier IS NOT NULL"; $result_array = array(); $count = 0; //echo $query."
"; $result = mysql_query($query, $dbh); while ($row = mysql_fetch_array($result)) { //echo "$count"; $result_array[$count++] = $row; } if ($count > $parent_index) { //echo "Yes"; return $result_array[$parent_index]; } return false; } function YartLog($str) { if ($_SERVER['REMOTE_ADDR'] == '220.245.174.83') { //print $str."
"; } } ?>